package com.zwz.service.impl;

import com.zwz.entity.RiskInfoMain;
import com.zwz.mapper.RiskInfoMainMapper;
import com.zwz.service.RiskInfoMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class RiskInfoMainServiceImpl implements RiskInfoMainService {

    private final RiskInfoMainMapper mapper;

    @Autowired
    public RiskInfoMainServiceImpl(RiskInfoMainMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void createRiskInfo(RiskInfoMain riskInfo) {
        if (riskInfo.getCompanyId() == null) {
            throw new IllegalArgumentException("必须关联企业ID");
        }
        mapper.insert(riskInfo);
    }

    @Override
    public void updateRiskInfo(RiskInfoMain riskInfo) {
        if (riskInfo.getId() == null) {
            throw new IllegalArgumentException("更新必须指定ID");
        }
        mapper.update(riskInfo);
    }

    @Override
    public void deleteRiskInfo(Integer id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("无效ID");
        }
        mapper.deleteById(id);
    }

    @Override
    public RiskInfoMain getRiskInfoById(Integer id) {
        return mapper.selectById(id);
    }
}